<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/8/16
 * Time: 09:52
 */

namespace app\api\model;


use traits\model\SoftDelete;

class ProductImage extends BaseModel
{
    use SoftDelete;
    protected $autoWriteTimestamp = true;
    protected $createTime =false;
    protected $updateTime = false;
    protected $hidden= ['img_id','product_id','delete_time'];
    /**
     * 与image表一对一关联
     * @return \think\model\relation\BelongsTo
     */
    public function imgUrl(){
        return $this->belongsTo('Image','img_id','id');
    }

    /**
     * 获取图片id
     * @param $product_id
     * @return false|\PDOStatement|string|\think\Collection
     */
    public static function getImgByProductId($product_id){
        $result =  self::where('product_id','=',$product_id)->select();
        foreach ($result as $value){
            $value->visible(['img_id']);
        }
        return $result;
    }
}